const path = require('path');
const webpack = require('webpack');
const htmlWebpackPlugin = require('html-webpack-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const vueLoaderConfig =require('./src/vue.config');
function resolve (dir) {
  return path.join(__dirname, '..', dir)
}
function assetsPath (_path) {
  return path.posix.join('static', _path)
}
module.exports = {
  mode: 'development', // 开发模式不压缩代码，方便调试
  entry: './src/main.js', // 入口文件
  output: {
    path: path.join(__dirname, 'dist'),
    filename: 'main.js'
  },
  resolve: {
    extensions: ['.js', '.vue'],
    alias: {
      'vue$': 'vue/dist/vue.esm.js',
      '@': resolve('src'),
    }
  },
  module: {
    // noParse: /\.json$/,
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: vueLoaderConfig
      },
      {
        test: /\.css$/,
        loader: "style-loader!css-loader"
      },
      {
        test: /\.(png|jpe?g|gif|svg|hdr)(\?.*)?$/,
        loader: 'url-loader',
        include: [resolve('static'),resolve('src')],
        options: {
          limit: 100000,
          name: assetsPath('img/[name].[hash:7].[ext]')
        }
      },
      {
        test: /\.(jpg|png|gif|xml|hdr)$/,
        use: [{
          loader: 'file-loader',
          options: {
            name() {
              return '[name].[ext]';
            },
            outputPath: 'static/'
          }
        }]
      }
    ]
  },
  //百度地图配置20180518
  externals: {
    "BMap": "BMap"
  },
  devServer: {
    contentBase: path.join(__dirname, 'dist')
  },
  plugins: [
    new VueLoaderPlugin(),
    new htmlWebpackPlugin({
      template: './src/index.html',
      filename: 'index.html'
    })
  ]
};
